'''
import random
n = 100
nums = list(range(n))
random.shuffle(list(range(n)))
'''


nums_0 = [3,5,1,7,9,6,8]
#way_1简单选择排序:
nums = nums_0[:]
for n in range(len(nums)-1):
    MaxIndex = n
    for i,v in enumerate(nums[n+1:]):
        if nums[MaxIndex] < v:
            MaxIndex = i+n+1
    if MaxIndex != n:
        nums[n],nums[MaxIndex] = nums[MaxIndex],nums[n]
print('原数组顺序：\n',nums_0,'\nway_1 简单选择排序结果：\n',nums)


#way_2 二元选择排序:
nums = nums_0[:]
for n in range(len(nums)//2):
    MaxIndex = n
    MinIndex = -1-n
    OriMinInd = MinIndex
    if nums[MaxIndex] < nums[MinIndex]:
        MaxIndex, MinIndex= MinIndex, MaxIndex
    for i,v in enumerate(nums[n+1:OriMinInd]):
        if nums[MaxIndex] < v:
            MaxIndex = i+n+1
        elif nums[MinIndex] > v:
            MinIndex = i+n+1
    if nums[MaxIndex] == nums[MinIndex]:
            break
    if MaxIndex != n:
        nums[n],nums[MaxIndex] = nums[MaxIndex],nums[n]
    if MinIndex != OriMinInd:
        nums[OriMinInd],nums[MinIndex] = nums[MinIndex],nums[OriMinInd]
print('way_2 二元选择排序结果：\n',nums)
